﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IFViewDetail.KuaiQi.Others;
using ZedGraph;
using IFClientDLL;
using System.Threading;

namespace FrmTryIF.Ctl.Calc.CtlDataImage
{
    public partial class CtlZedGraphBase : CtlBase
    {
        public CtlZedGraphBase()
        {
            InitializeComponent();
        }
        public override void InitTryIF(ITryIF tryIF)
        {
            base.InitTryIF(tryIF);
        }
        public const int _YStep = 3;
        public double CalcXDataByDateTime(DateTime dt)
        {
            if (dt.Hour >= 13)
            {
                return XDate.DateTimeToXLDate(dt.AddHours(-1).AddMinutes(-30));
            }
            else
            {
                return XDate.DateTimeToXLDate(dt);
            }
        }
        protected void SetXAxis(ZedGraphControl zedGraphControl1)
        {
            zedGraphControl1.GraphPane.XAxis.Scale.MinAuto = false;
            zedGraphControl1.GraphPane.XAxis.Scale.MaxAuto = false;
            zedGraphControl1.GraphPane.XAxis.Scale.Min = XDate.DateTimeToXLDate(_tryif.DataInfo.日期.Date.AddHours(9).AddMinutes(0));
            zedGraphControl1.GraphPane.XAxis.Scale.Max = XDate.DateTimeToXLDate(_tryif.DataInfo.日期.Date.AddHours(13).AddMinutes(45));
            //zedGraphControl1.GraphPane.XAxis.Scale.MajorStepAuto = false;
            //zedGraphControl1.GraphPane.XAxis.Scale.MinorStepAuto = true;
            //zedGraphControl1.GraphPane.XAxis.Scale.MinorStep = 0.25;
            //zedGraphControl1.GraphPane.XAxis.Scale.MinorUnit = DateUnit.Hour;
            //zedGraphControl1.GraphPane.XAxis.Scale.Mag = 1;
            zedGraphControl1.GraphPane.XAxis.Scale.MajorUnit = DateUnit.Hour;
            zedGraphControl1.GraphPane.XAxis.Scale.MajorStep = 0.25f;
            //zedGraphControl1.GraphPane.XAxis.Scale.MinGrace = 1;

            

            
            
        }
        protected void SetXAxisFormat(ZedGraphControl zedGraphControl1)
        {
         
            zedGraphControl1.GraphPane.XAxis.ScaleFormatEvent += new Axis.ScaleFormatHandler(XAxis_ScaleFormatEvent);
        }

        public string XAxis_ScaleFormatEvent(GraphPane pane, Axis axis, double val, int index)
        {
            var dt = XDate.XLDateToDateTime(val);
            if (dt.CompareTo(dt.Date.AddHours(11).AddMinutes(30)) > 0)
            {
                return dt.AddHours(1).AddMinutes(30).ToShortTimeString();
            }
            return dt.ToShortTimeString();
        }
       
    }
}
